package com.cn.wanxi.util;

import java.io.*;

public class IO {
      public static File file;
//    public static File getFile(String fileName) {
//        return new File(PAHT.PAHT.getPath()+"//"+fileName);
//    }

    /**
     * 1创建记事本
     * 2将数据存于记事本
     * 3数据来源于记事本，读取
     * 4封装数据到CompanyModel
     */
    public static File createNotepad(String noteName) {
        File file = new File(PAHT.PAHT.getPath());
        if(!file.exists()){
            file.mkdirs();
        }
        File file2 = new File(PAHT.PAHT.getPath(),noteName);
        try {
            file2.createNewFile();
            return file2;
        } catch (IOException e) {
            e.printStackTrace();
        }
        return null;
    }

    /**
     *  读取文本
     * @return
     */
    public static String readNotepad() {
        String str = "";
        String strr = "";
        try {
            BufferedReader br = new BufferedReader(new FileReader(file));
            while ((str = br.readLine()) != null) {
                strr += str;
            }
            return strr;
        } catch (IOException e) {
            e.printStackTrace();
        }
        return null;
    }

    /**
     *  写入文本
     * @param
     */
    public static void writeNotepad(String text,String noteName) {
        file = createNotepad(noteName);
        try {
            BufferedWriter bw = new BufferedWriter(new FileWriter(file));
            bw.write(text);
            bw.flush();
            bw.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
